import java.util.ArrayList;


public class Part
{
	private int code;
	private String title;
	private double buyPrice;
	private double sellPrice;
	private String manufactory;
	
	 ArrayList<Car> cars = new ArrayList<Car>();
	
	public Part(int code, String title, double buyPrice, String manufactory) {

		this.code = code;
		this.title = title;
		this.buyPrice = buyPrice;
		this.sellPrice = calculateSellPrice(buyPrice);
		this.manufactory = manufactory;
		
	}
	
	private double calculateSellPrice(double buyPrice)
	{
		return buyPrice + (buyPrice * 0.50);
	}
	
	public void addCar(Car car)
	{
		cars.add(car);

		
		if(cars.get(0) != null)
			cars.get(0).getParts().add(this);
		
	}
	
	public void partInfo()
	{
		System.out.println("Code: " + this.code);
		System.out.println("Title: " + this.title);
		System.out.println("Buyed Price: " + this.buyPrice);
		System.out.println("Selling Price: " + this.sellPrice);
		System.out.println("Manufactory: " + this.manufactory);
		System.out.println();
		System.out.println("=== Cars ===");
		carInfo();
		System.out.println();
	}
	
	public void  searchPartsByCar(String car)
	{
		for(int i = 0; i < cars.size(); i++)
		{
			if(cars.get(i).getMarc().equalsIgnoreCase(car))    // if marc == car 
			{
				this.partInfo();
			}
		}
	}

	private void carInfo()
	{
		for(int i = 0; i < cars.size(); i++)
		{
			if(cars.get(i) != null)
			{
				cars.get(i).carInfoForParts();
			}
		}
	}

	     void partInfoForCars()
	{
		System.out.println("Code: " + this.code);
		System.out.println("Title: " + this.title);
		System.out.println("Buyed Price: " + this.buyPrice);
		System.out.println("Selling Price: " + this.sellPrice);
		System.out.println("Manufactory: " + this.manufactory);
		System.out.println();
	}
}
